package com.mall.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.goods.model.Brand;
import com.mall.goods.service.BrandService;
import com.mall.util.RespResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @description:
 * @author: ljr
 * @time: 2021/9/4 0:36
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;


    @PostMapping
    public RespResult<Void> add(@RequestBody Brand brand){
        brandService.save(brand);
        return RespResult.ok();
    }


    @PutMapping
    public RespResult<Void> update(@RequestBody Brand brand){
        brandService.updateById(brand);
        return RespResult.ok();
    }

    @DeleteMapping("/{id}")
    public RespResult<Void> update(@PathVariable("id") String id){
        brandService.removeById(id);
        return RespResult.ok();
    }



    @PostMapping("/search/{page}/{size}")
    public RespResult<Void> searchPage(@PathVariable("page") Long pageNum,
                                @PathVariable("size") Long pageSize,
                                @RequestBody Brand brand){
        Page<Brand> page =  brandService.queryPage(brand, pageNum,  pageSize);
        return RespResult.ok(page);
    }

}
